<?php

if (!defined('MOODLE_INTERNAL')) {
    die('Direct access to this script is forbidden.');
}

global $CFG;
require_once($CFG->dirroot . '/blocks/formal_langs/grammar_pattern.php');

class block_formal_langs_grammar_pattern_test extends UnitTestCase {

    public function test_parser_rule_constructor() {
        $alternatives = array();
        $elements_a = array('ID', 'term', 'NUM', 'expr');
        $alternatives[] = new block_formal_langs_parser_rule_alternative($elements_a);
        $elements_b = array('ID', 'ID', 'NUM', 'COLON');
        $alternatives[] = new block_formal_langs_parser_rule_alternative($elements_b);
        
        $rule = new block_formal_langs_parser_rule('test', $alternatives, 'description');
        $this->assertNotNull($rule);
        $this->assertIsA($rule, 'block_formal_langs_parser_rule');

        $this->assertEqual($rule->name(), 'test');
        $this->assertEqual($rule->alternatives(), $alternatives);
        
    }

    public function test_parser_rule_alternative_constructor_1() {
        $elements = array('ID', 'term', 'NUM', 'expr');
        $alt = new block_formal_langs_parser_rule_alternative($elements);

        $this->assertNotNull($alt);
        $this->assertIsA($alt, 'block_formal_langs_parser_rule_alternative');

        $this->assertEqual($alt->elements(), $elements);
        $this->assertEqual($alt->num(), -1);
        $alt->set_num(2);
        $this->assertEqual($alt->num(), 2);
        $this->assertEqual($alt->rule_num(), -1);
        $alt->set_rule_num(1);
        $this->assertEqual($alt->rule_num(), 1);
        
    }
}
 ?>